﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PingYou
{
    public class CommonMethod
    {
        #region public static string ECountFileSize(long fileSize) 反向计算文件大小函数
        /// <summary>
        /// 计算文件大小函数(保留两位小数),fileSize为10KB
        /// </summary>
        /// <param name="Size">初始文件大小</param>
        /// <returns></returns>
        public static long ECountFileSize(string fileSize, string unit)
        {
            if (string.IsNullOrEmpty(fileSize))
            {
                return 0;
            }
            long Size = 0;
            double FactSize = 0;
            if (fileSize.IndexOf("GB") > -1)
            {
                fileSize = fileSize.Replace("GB", "");
                FactSize = Convert.ToDouble(fileSize) * 1024 * 1024 * 1024;
            }
            else if (fileSize.IndexOf("MB") > -1)
            {
                fileSize = fileSize.Replace("MB", "");
                FactSize = Convert.ToDouble(fileSize) * 1024 * 1024;
            }
            else if (fileSize.IndexOf("MB") > -1)
            {
                fileSize = fileSize.Replace("KB", "");
                FactSize = Convert.ToDouble(fileSize) * 1024;
            }
            else if (fileSize.IndexOf("B") > -1)
            {
                fileSize = fileSize.Replace("KB", "");
                FactSize = Convert.ToDouble(fileSize);
            }
            if (unit == "GB")
            {
                Size = (long)(FactSize / 1024.00 / 1024.00 / 1024.00);
            }
            if (unit == "MB")
            {
                Size = (long)(FactSize / 1024.00 / 1024.00);
            }
            if (unit == "KB")
            {
                Size = (long)(FactSize / 1024.00);
            }
            return Size;
        }
        #endregion
    }
}
